<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Str;

class CsmMakeCommand extends Command
{
    /**
     * 指令名称
     *
     * @var string
     */
    protected $name = 'make:csm';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create a new controller、service、model class';

    protected $signature = 'make:csm {name}';

    public function handle()
    {
        $class = $this->argument('name');
        $this->call('make:model', [
            'name' => $class . 'Model',
            '--force' => true,
            '--table' => Str::snake(lcfirst(array_slice(explode('/', $class), -1, 1)[0]))
        ]);
        $this->call('make:service', ['name' => $class . 'Service', '-m' => $class . 'Model', '--force' => true]);
        $this->call('make:controller', ['name' => $class . 'Controller', '--service' => $class . 'Service', '--force' => true]);
    }
}
